package user

import (
	"fmt"
	"github.com/gin-gonic/gin"
)

func queryFixer(c *gin.Context, k string, v []string, p []any) (w, k1 string, p1 []any, ctn bool, err error) {
	err = fmt.Errorf("key not match")
	k1 = k
	p1 = p
	switch k {
	case "id":
		err = nil
		qid := c.Query("id")
		ctn = qid == "0" || qid == ""
	case "sex[]":
		w = ""
		k1 = "sex"
		err = nil
		ctn = false
	case "role[]":
		w = ""
		k1 = "role"
		err = nil
		ctn = false
	case "deleted_at[]":
		k1 = "deleted_at"
		err = nil
		ctn = true
		if len(v) == 1 {
			if v[0] == "0" {
				w = fmt.Sprintf("and %s = 0", k1)
			} else {
				w = fmt.Sprintf("and %s > 0", k1)
			}
		}
	}
	return
}
